<template>
	<view>
		<u-navbar back-text="" title="我的余额">
			<view class="collection_type_title" slot='right' @click="navTo">
				收款方式
			</view>
		</u-navbar>
		<view class="balance_top">
			<view class="top_pic">
				¥{{balance.balance}}
			</view>
			<view class="top_left">
				<image src="../../../static/img/yue_icon.png" class="yue_icon" mode=""></image>
				<u-input style="color: #FFFFFF;" placeholder="请输入提现金额" placeholder-style='color: #fff;' v-model="value"
					type="number" :border="false" class="u-border-bottom" />
				<u-button @click="handWithdrawal" style="color: #FF365D;margin-left: 30rpx;" shape="circle">立即提现
				</u-button>
			</view>
			<view class="top_bottom">
				<view class="item">
					<view class="title">
						累计收益(元)
					</view>
					<view class="summary">
						¥{{balance.income}}
					</view>
				</view>
				<u-line color='#fff' length='59' direction='col'></u-line>
				<view class="item">
					<view class="title">
						已提现(元)
					</view>
					<view class="summary">
						¥{{balance.withdrawal}}
					</view>
				</view>
			</view>
		</view>
		<u-tabs-swiper class="u-border-bottom" active-color='#FF365D' :current="current" @change="tabsChange" ref="tabs"
			:list="listTab" :is-scroll="false">
		</u-tabs-swiper>
		<u-empty v-if="list.length==0"></u-empty>
		<view class="int_list" v-else>
			<view class="item u-border-bottom" v-for="item in list" :key='item.id'>
				<view class="right u-border-right">
					<image class="icon" :src="item.handlUrl" mode="">
					</image>
					<view class="content">
						{{item.operationName}}
					</view>
				</view>
				<view class="num">
					{{item.operation==3?'-':'+'}}{{item.money}}
				</view>
			</view>
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
	import initData from '@/mixin/initData.js'
	export default {
		mixins: [initData],
		data() {
			return {
				value: '',
				listTab: [{
					name: '收益记录'
				}, {
					name: '提现记录'
				}],
				current: 0,
				balance: {}
			};
		},
		onLoad() {
			this.apiUrl = 'appBalanceDetails/incomeDetails'
			this.init()
			this.miXinInit()
		},
		methods: {
			handWithdrawal() {
				console.log(this.value)
				if (!this.balance.balance) {
					uni.showToast({
						title: '当前余额0,无法提现',
						icon: 'none'
					})
					return
				}
				if (!this.value) {
					uni.showToast({
						title: '请输入金额!',
						icon: 'none'
					})
					return
				}
				const reg = /(?:^[1-9]([0-9]+)?(?:\.[0-9]{1,2})?$)|(?:^(?:0)$)|(?:^[0-9]\.[0-9](?:[0-9])?$)/
				if (!reg.test(this.value)) {
					uni.showToast({
						title: '输入不合法!',
						icon: 'none'
					})
					return
				}
				if (this.value < 0.1) {
					uni.showToast({
						title: '最低提现0.1',
						icon: 'none'
					})
					return
				}
				uni.navigateTo({
					url: '/pages/my/balance/withdrawal?money=' + this.value
				})
			},
			navTo() {
				uni.navigateTo({
					url: '/pages/my/balance/collectionType'
				})
			},
			init() {
				this.$u.api.myBalanceDetails().then(res => {
					console.log(res, 'res')
					this.balance = res
				})
			},
			// 请求前的参数处理
			beforeInit() {
				// this.apiUrl = "appBalanceDetails/incomeDetails";
				let params = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
				};

				this.params = {
					...params
				};
			},
			// GET /app/appBalanceDetails/incomeDetails
			// tabs通知swiper切换
			tabsChange(index) {
				this.toReset()
				this.current = index;
				if (index == 0) {
					this.apiUrl = 'appBalanceDetails/incomeDetails'
				} else {
					this.apiUrl = 'appBalanceDetails/withdrawalDetails'
				}
				this.miXinInit()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.int_list {
		padding: 0 30rpx;

		.item {
			padding: 24rpx 0;

			display: flex;
			align-items: center;
			justify-content: space-between;

			.right {
				display: flex;
				padding-right: 30rpx;
				margin-right: 30rpx;
				width: 100%;
			}

			.num {
				color: #FF0E3D;
				font-size: 32rpx;
				width: 20%;
			}

			.content {
				font-size: 21rpx;
				color: #ACACAC;
				@include ellipsisMultiline(2);
				min-width: 80%;
			}

			.icon {
				width: 54rpx;
				height: 54rpx;
				min-width: 54rpx;
				min-height: 54rpx;
				margin-right: 20rpx;
				border-radius: 50%;
			}
		}
	}

	.balance_top {
		background: url(../../../static/img/mybg.png) no-repeat;
		background-size: 100% 100%;
		// height: 400rpx;
		text-align: center;
		padding: 40rpx 0;

		.top_bottom {
			display: flex;
			align-items: center;
			padding: 0 50rpx;
			margin-top: 44rpx;
			justify-content: space-around;

			.item {
				display: flex;
				flex-direction: column;
				align-items: center;

				.summary {
					font-size: 20rpx;
					color: #FFFFFF;
					margin-top: 10rpx;
				}

				.title {
					font-size: 26rpx;
					color: #FFFFFF;
				}
			}
		}

		.top_left {
			display: flex;
			align-items: center;
			padding: 0 20rpx;
			margin-top: 45rpx;

			.yue_icon {
				width: 32rpx;
				height: 32rpx;
				margin-right: 10rpx;
			}
		}

		.top_pic {
			color: #FFFFFF;
			font-size: 66rpx;
			font-weight: 600;
		}
	}

	.collection_type_title {
		color: $u-type-primary;
		margin-right: 20rpx;
	}
</style>
